﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Antlr.Runtime;

namespace Graph2
{
	public class StandardFunction : Function
	{
		String m_Expression;

		public StandardFunction(String expression)
		{
			m_Expression = expression.Replace(" ", "");

			graph2Lexer lexer = new graph2Lexer(new ANTLRStringStream(m_Expression));
			graph2Parser parser = new graph2Parser(new CommonTokenStream(lexer));

			try
			{
				RuleReturnScope rrs = parser.expression();
				if (parser.HasError)
				{
					throw new Function.ParseException(parser.ErrorMessage, parser.ErrorPosition);
				}
			}
			catch (Function.ParseException)
			{
				throw;
			}
			catch (Exception err)
			{
				throw new Function.ParseException(err.Message, "");
			}
		}

		public override String Name
		{
			get
			{
				return "f(x)=" + m_Expression;
			}
		}
	}
}
